import http from './http/index'

export const createRole = new class {
  apis = ['account.CreateRole']
  fn = (page, { name }) => {
    return http.post(page, [{
      service: this.apis[0],
      args: { name }
    }])
  }
}()

export const removeRole = new class {
  apis = ['account.RemoveRole']
  fn = (page, { id }) => {
    return http.post(page, [{
      service: this.apis[0],
      args: { id }
    }])
  }
}()

export const editRole = new class {
  apis = ['account.EditRole']
  fn = (page, { id, name }) => {
    return http.post(page, [{
      service: this.apis[0],
      args: { id, name }
    }])
  }
}()

export const roleAddPages = new class {
  apis = ['account.RoleAddPages']
  fn = (page, { roleId, pages }) => {
    return http.post(page, [{
      service: this.apis[0],
      args: { roleId, pages }
    }])
  }
}()

export const roleRemovePages = new class {
  apis = ['account.RoleDelPages']
  fn = (page, { roleId, pages }) => {
    return http.post(page, [{
      service: this.apis[0],
      args: { roleId, pages }
    }])
  }
}()

export const rolesPage = new class {
  apis = ['account.GetRolesPage']
  fn = (page, { roleId }) => {
    return http.post(page, [{
      service: this.apis[0],
      args: {
        roleId
      }
    }])
  }
}()

export const getRoleManagerInfo = new class {
  apis = ['account.ListRoles', 'account.GetMenuTree', 'account.GetRolesPage']
  fn = (page) => {
    return http.post(page, [{
      service: this.apis[0],
      args: { storeFirst: true }
    }, {
      service: this.apis[1]
    }, {
      service: this.apis[2]
    }])
  }
}()
